import { Datetime } from 'vux'

export default {
  name:"FundCenter",
  components:{Datetime},
  data(){
    return {
      fold1: true,
      fold2: true,
      startDate:'',
      endDate:'',
      replenishDetail:[],
      salesDetail:[],
      detail:{}
    }
  },
  methods:{
    change () {
      if(this.startDate>this.endDate){
        this.endDate = this.startDate;
      }
    },
    foldFn1(){
      this.fold1 = !this.fold1;
    },
    foldFn2(){
      this.fold2 = !this.fold2;
    },
    comfirm(){
      let startString = Date.parse(this.startDate);
      let endString = Date.parse(this.endDate);
      let day = (endString - startString)/(1000*24*3600); //秒
      if(this.startDate>this.endDate){
        this.$vux.toast.text('开始时间不能大于结束时间', 'center');
      }
      if(day>365){
        this.$vux.toast.text('单次只能查询1年内的数据', 'center');
      }
      this.initData();
    },
    initData(){
      this.$ajax.get("report/capital",(res) => {
        if(res.code==200){
          this.detail = res.data;
          this.replenishDetail = res.data.replenishDetail;
          this.salesDetail = res.data.salesDetail;
        }else{
          this.$vux.toast.text(res.msg, 'center');
        }
      },{startTime:this.startDate+ ' ' + '00:00:00',endTime :this.endDate + ' ' + '23:59:59'});
    },
    getNowDate(){
      var date = new Date();
      var seperator1 = "-";
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var strDate = date.getDate();
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
      }
      var monthFirstDay =  year + seperator1 + month + seperator1 + '01';
      var currentdate = year + seperator1 + month + seperator1 + strDate;
      this.startDate = monthFirstDay + '';
      this.endDate = currentdate+'';
    },
    refresh(){
      this.$refs.scroll.finishPullToRefresh();
    }
  },
  created:function(){
    this.getNowDate();
  },
  mounted(){
    this.initData();
  }
}
